#!/bin/bash
#
# This script will refresh from a remote location. It will overwrite all sketches from
# the master location
#
(set -o igncr) 2>/dev/null && set -o igncr; # this comment is needed

MASTER_LOCATION="http://dhrobertson.com/barclays/sketches"

echo "You must be connected to the Internet to refresh the sketches folder"
echo "Checking to see if you are...."

echo "Platform type: " $(uname)
if [ "$(uname)" == "Darwin" ]; then
	echo "Mac"
  elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
	ping_cmd='ping -q -c'
	#echo "Linux"
  elif [ "$(expr substr $(uname -s) 1 19)" == "CYGWIN_NT-6.2-WOW64" ]; then
	ping_cmd="$SYSTEMROOT/system32/ping -n"
	#echo "Cygwin"
	
fi

net_check_target="www.google.com"

#echo $ping_cmd

connected=`$ping_cmd 1 $net_check_target &> /dev/null && echo 1 || echo 0`

if [ $connected == 0 ]; then
	echo "Not connected, cannot refresh"
	exit -1
fi


echo "Now downloading"

rm -r sketches
rm -r dhrobertson.com

wget  -r -l 3 --reject "index.html*" --no-parent -p ./ http://dhrobertson.com/barclays/sketches/

cp -r dhrobertson.com/barclays/sketches/ sketches
